package net.hcpme.db;

import java.sql.SQLException;

import net.hcpme.dao.Message;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper;
import com.j256.ormlite.support.ConnectionSource;
import com.j256.ormlite.table.TableUtils;

public class DatabaseHelper extends OrmLiteSqliteOpenHelper {

    private static final String TAB = "DatabaseHelper";

    private static final String database_name = "hcpme.db";
    private static final int database_version = 1;

    public DatabaseHelper(Context context) {
        super(context, database_name, null, database_version);
    }

    @Override
    public void onCreate(SQLiteDatabase db, ConnectionSource connectionSource) {
        try {
            TableUtils.createTable(connectionSource, Message.class);
        } catch (SQLException e) {
            Log.d(TAB, "create db file!");
            e.printStackTrace();
        }
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, ConnectionSource connectionSource, int arg2, int arg3) {
        try {
            TableUtils.dropTable(connectionSource, Message.class, true);
        } catch (SQLException e) {
            Log.d(TAB, "update db file!");
            e.printStackTrace();
        }
    }

    @Override
    public void close() {
        super.close();
    }

}
